
import os
import xml.etree.ElementTree as ET
import conftest



def set_report_xml_on_jenkins():
    # 创建一个根元素
    root = ET.Element("environment")

    # 创建子元素并添加数据
    parameters = [
        {"key": "浏览器", "value": "谷歌"},
        {"key": "浏览器版本", "value": "89.0.4389.128"},
        {"key": "项目环境", "value": "测试环境"},
        {"key": "项目地址", "value": "http://192.168.74.138:9090/"},
        {"key": "测试人员", "value": "吴彦祖"},
    ]
    for param in parameters:
        parameter = ET.SubElement(root, "parameter")
        ET.SubElement(parameter, "key").text = param["key"]
        ET.SubElement(parameter, "value").text = param["value"]

    # 生成XML树对象
    tree = ET.ElementTree(root)

    # 创建XML文档并写入文件
    tree = ET.ElementTree(root)
    path=r"/var/jenkins_home/workspace/demo_001/allure_html"
    allure_xml_file = os.path.join(path, 'environment.xml')
    tree.write(allure_xml_file, encoding="utf-8", xml_declaration=True)